package com.chixing.config;

import com.chixing.interceptor.AutoIdempotentInterceptor;
import com.chixing.interceptor.LoggingInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Autowired
    private LoggingInterceptor loggingInterceptor;
    @Autowired
    private AutoIdempotentInterceptor autoIdempotentInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry){
        // addPathPatterns(要拦截的url)  ， 要以 / 开头
        //excludePathPatterns(不需要被拦截的url) ， 要以 / 开头
        registry.addInterceptor(loggingInterceptor).addPathPatterns("/orders/**");
        registry.addInterceptor(autoIdempotentInterceptor).addPathPatterns("/order-transactions/**","/orders/**");
        registry.addInterceptor(autoIdempotentInterceptor).addPathPatterns("/refunds/**");
        registry.addInterceptor(autoIdempotentInterceptor).addPathPatterns("/order-transactions/**","/orders/**","/room-inventory/**");
        System.out.println("注入验证幂等性拦截器成功");
    }
}
